
package NovoSISAM.Gui;

import NovoSISAM.Dao.FuncionarioDao;
import NovoSISAM.Model.Funcionarios;
import javax.swing.JOptionPane;

/**
 *
 * @author Thiago
 */
public class Cadastro_Funcionarios extends javax.swing.JInternalFrame {
    Funcionarios funcionario;
    /** Creates new form Cadastro_Funcionarios */
    public Cadastro_Funcionarios() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel11 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtnascimento = new javax.swing.JTextField();
        txtnome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtemail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtnaturalidade = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtcpf = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtrg = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtendereco = new javax.swing.JTextField();
        txttelefone = new javax.swing.JTextField();
        txtcontrato = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cbocargo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        botaoCancelar = new javax.swing.JButton();
        botaoExcluir = new javax.swing.JButton();
        botaoN = new javax.swing.JButton();
        botaoSalvar = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        botaoAlterar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Funcionarios - SISAM");

        jLabel11.setText("Naturalidade:");

        jLabel4.setText("Endereço:");

        jLabel3.setText("Nome:");

        jLabel12.setText("Data Contrato:");

        txtCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCodigoFocusLost(evt);
            }
        });

        jLabel7.setText("Telefone:");

        jLabel13.setText("Código:");

        jLabel6.setText("CPF:");

        jLabel5.setText("RG:");

        jLabel8.setText("Email:");

        cbocargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "Administador SYS", "Farmaceutico", "Parceiro", "Recepcionista" }));

        jLabel9.setText("Cargo:");

        jLabel10.setText("D.Nasc:");

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 1, 24));
        jLabel1.setForeground(new java.awt.Color(0, 51, 204));
        jLabel1.setText("Funcionários");

        botaoCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/NovoSISAM/Gui/Imagens/cancelar.jpg"))); // NOI18N
        botaoCancelar.setText("Cancelar");
        botaoCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoCancelar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        botaoExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/NovoSISAM/Gui/Imagens/excluir.jpg"))); // NOI18N
        botaoExcluir.setText("Excluir");
        botaoExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoExcluir.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoExcluirActionPerformed(evt);
            }
        });

        botaoN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/NovoSISAM/Gui/Imagens/novo.jpg"))); // NOI18N
        botaoN.setText("Novo");
        botaoN.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoN.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoN.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoNActionPerformed(evt);
            }
        });

        botaoSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/NovoSISAM/Gui/Imagens/salvar.jpg"))); // NOI18N
        botaoSalvar.setText("Salvar");
        botaoSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoSalvar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        jLabel14.setText("(somente números)");

        jLabel15.setText("DD/MM/AAAA");

        jLabel16.setText("(somente números)");

        jLabel17.setText("DD/MM/AAAA");

        botaoAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/NovoSISAM/Gui/Imagens/alterar.jpg"))); // NOI18N
        botaoAlterar.setText("Alterar");
        botaoAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoAlterar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel8)
                                .addComponent(jLabel7)
                                .addComponent(jLabel4)
                                .addComponent(jLabel9))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jLabel5))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel10)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbocargo, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtemail, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(txttelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jLabel16)
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel12)
                                        .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addGap(10, 10, 10)
                                    .addComponent(txtcontrato, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtnome, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtendereco, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtrg, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtnascimento, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel14)
                                        .addComponent(jLabel15))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel11)
                                        .addComponent(jLabel6))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtnaturalidade)
                                        .addComponent(txtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap(87, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(101, Short.MAX_VALUE)
                .addComponent(botaoN, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botaoSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(botaoAlterar)
                .addGap(14, 14, 14)
                .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoAlterar, botaoCancelar, botaoExcluir, botaoSalvar});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel12, jLabel17});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(17, 17, 17)
                        .addComponent(jLabel5)
                        .addGap(12, 12, 12)
                        .addComponent(jLabel10)
                        .addGap(9, 9, 9)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(jLabel8))
                            .addComponent(jLabel7))
                        .addGap(36, 36, 36)
                        .addComponent(jLabel9))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtnome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtrg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(txtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtnascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11)
                                .addComponent(txtnaturalidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtendereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txttelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel16)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(7, 7, 7)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(13, 13, 13)
                                                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(txtcontrato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jLabel12))))
                        .addGap(11, 11, 11)
                        .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbocargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botaoN, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botaoExcluir)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(botaoSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                                .addGap(89, 89, 89))
                            .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {botaoCancelar, botaoExcluir, botaoN, botaoSalvar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
          if  (txtCodigo.getText().isEmpty()){
                    botaoAlterar.setEnabled(false);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(false);
                    botaoN.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    destravacampos();
                }
            else
                {
                    botaoAlterar.setEnabled(true);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(true);
                    botaoN.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    travacampos();
                }       
}//GEN-LAST:event_botaoCancelarActionPerformed

    private void botaoNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoNActionPerformed
            limpacampos();
            destravacampos();
            txtCodigo.setEditable(true);
            txtCodigo.requestFocus();
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(false);
            botaoN.setEnabled(false);
            botaoSalvar.setEnabled(true);
    }//GEN-LAST:event_botaoNActionPerformed

    private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed
           funcionario = new Funcionarios();
            funcionario.setCod_funcionario(Integer.parseInt(txtCodigo.getText()));
            funcionario.setNome(txtnome.getText());
            funcionario.setEndereco(txtendereco.getText());
            funcionario.setCpf(txtcpf.getText());
            funcionario.setRg(txtrg.getText());
            funcionario.setTelefone(txttelefone.getText());
            funcionario.setData_nascimento(txtnascimento.getText());
            funcionario.setEmail(txtemail.getText());
            funcionario.setNaturalidade(txtnaturalidade.getText());
            funcionario.setCargo(cbocargo.getSelectedIndex());
            funcionario.setData_contrato(txtcontrato.getText());

            if (txtCodigo.isEditable()){
               if(FuncionarioDao.inserirfuncionario(funcionario)){
                    JOptionPane.showMessageDialog(null,"funcionario Cadastrado com Sucesso");
               }else{
                    JOptionPane.showMessageDialog(null, "Nao foi possivel Salvar");
               }
                limpacampos();
                travacampos();
                botaoAlterar.setEnabled(false);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(false);
                botaoN.setEnabled(true);
                botaoSalvar.setEnabled(false);

            }else{
                    FuncionarioDao.AtualizarFuncionario(funcionario);
                    travacampos();
                    botaoAlterar.setEnabled(true);
                    botaoCancelar.setEnabled(true);
                    botaoExcluir.setEnabled(true);
                    botaoN.setEnabled(true);
                    botaoSalvar.setEnabled(false);
            }        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSalvarActionPerformed

    private void txtCodigoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodigoFocusLost
                int codFuncionario = Integer.parseInt(txtCodigo.getText());
          //funcionario =  FuncionarioDao.localizarFuncionario(codFuncionario);
          if ((funcionario =  FuncionarioDao.localizarFuncionario(codFuncionario)) != null) {
                txtnome.setText(funcionario.getNome());
                txtcpf.setText(funcionario.getCpf());
                txtendereco.setText(funcionario.getEndereco());
                txtnascimento.setText(funcionario.getData_nascimento());
                txttelefone.setText(funcionario.getTelefone());
                txtemail.setText(funcionario.getEmail());
                txtrg.setText(funcionario.getRg());
                cbocargo.setSelectedIndex(funcionario.getCargo());
                txtnaturalidade.setText(funcionario.getNaturalidade());
                txtcontrato.setText(funcionario.getData_contrato());

                travacampos();
                botaoAlterar.setEnabled(true);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(true);
                botaoN.setEnabled(true);
                botaoSalvar.setEnabled(false);
          }  
    }//GEN-LAST:event_txtCodigoFocusLost

    private void botaoExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoExcluirActionPerformed
        if (funcionario == null) {
            JOptionPane.showMessageDialog(this, "Selecione um funcionário para excluir!");
            return;
        } else {
            boolean result = JOptionPane.showInternalConfirmDialog(
                    this, "Deseja realmente excluir este Funcionário?") == 0;
            if(result == true){
                funcionario.setCod_funcionario(Integer.parseInt(txtCodigo.getText()));
                FuncionarioDao.deleteFuncionario(funcionario);
                limpacampos();
                destravacampos();
                botaoAlterar.setEnabled(false);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(false);
                botaoN.setEnabled(true);
                botaoSalvar.setEnabled(true);
            }else
                return;
}//GEN-LAST:event_botaoExcluirActionPerformed
    }
        private void travacampos() {
            txtCodigo.setEditable(false);
            txtnome.setEditable(false);
            txtcpf.setEditable(false);
            txtnaturalidade.setEditable(false);
            txtemail.setEditable(false);
            txtendereco.setEditable(false);
            txtcontrato.setEditable(false);
            txtnascimento.setEditable(false);
            txttelefone.setEditable(false);
            cbocargo.setEnabled(false);
            txtrg.setEditable(false);
    }

        private void botaoAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarActionPerformed
            destravacampos();
            txtCodigo.setEditable(false);
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(true);
            botaoN.setEnabled(false);
            botaoSalvar.setEnabled(true);
}//GEN-LAST:event_botaoAlterarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoExcluir;
    private javax.swing.JButton botaoN;
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JComboBox cbocargo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtcontrato;
    private javax.swing.JTextField txtcpf;
    private javax.swing.JTextField txtemail;
    private javax.swing.JTextField txtendereco;
    private javax.swing.JTextField txtnascimento;
    private javax.swing.JTextField txtnaturalidade;
    private javax.swing.JTextField txtnome;
    private javax.swing.JTextField txtrg;
    private javax.swing.JTextField txttelefone;
    // End of variables declaration//GEN-END:variables
    

    private void destravacampos() {
            txtCodigo.setEditable(true);
            txtnome.setEditable(true);
            txtcpf.setEditable(true);
            txtnaturalidade.setEditable(true);
            txtemail.setEditable(true);
            txtendereco.setEditable(true);
            txtcontrato.setEditable(true);
            txtnascimento.setEditable(true);
            txttelefone.setEditable(true);
            cbocargo.setEnabled(true);
            txtrg.setEditable(true);
    }

    private void limpacampos() {
                txtCodigo.setText(null);
                txtnome.setText(null);
                txtcpf.setText(null);
                txtrg.setText(null);
                txtemail.setText(null);
                txtendereco.setText(null);
                txtnaturalidade.setText(null);
                txtnascimento.setText(null);
                txttelefone.setText(null);
                txtcontrato.setText(null);
                cbocargo.setSelectedIndex(0);
    }
    
}
